Click here to Skip to main content
15,896,118 members
Articles / Desktop Programming / XAML

Silverlight 1.0 Full JavaScript Intellisense

Rate me:
Please Sign up or sign in to vote.
3.81/5 (16 votes)
21 Dec 2007Ms-PL11 min read 31.9K   141   17  
An article about Silverlight 1.0 full JavaScript Intellisense
using System;
using System.Collections.Generic;
using System.Reflection;

namespace SiliverlightJavascriptIntelli
{
    public static class SilverlightTypeCollctor
    {
        public static List<SilverlightType> GetTypesToGenerateJavascriptFor()
        {
            List<SilverlightType> ReturnValues = new List<SilverlightType>();

            IterateOverAllTypesInAgclrAndConvertToSilverlightType(ReturnValues);

            return ReturnValues;
        }

        public static void IterateOverAllTypesInAgclrAndConvertToSilverlightType(List<SilverlightType> ReturnValues)
        {
            foreach (Type curCLRTypeToExtractTypeDataFrom in TypeHelper.agClrAssembly.GetTypes())
            {
                if (curCLRTypeToExtractTypeDataFrom.IsPublic)
                    ReturnValues.Add(ConvertCLRTypeToSilverlightType(curCLRTypeToExtractTypeDataFrom));
            }
        }

        public static SilverlightType ConvertCLRTypeToSilverlightType(Type curCLRTypeToExtractTypeDataFrom)
        {
            SilverlightType newSilverlightType = new SilverlightType();

            newSilverlightType.Name = TypeHelper.ConvertTypeToString(curCLRTypeToExtractTypeDataFrom);
            newSilverlightType.SetTypeHierhcy(curCLRTypeToExtractTypeDataFrom);
            newSilverlightType.CanBePrimitiveType = !TypeHelper.IsFromDependencyObject(curCLRTypeToExtractTypeDataFrom);

            IterateAndAddProperties(curCLRTypeToExtractTypeDataFrom, newSilverlightType);

            IterateAndAddMethods(curCLRTypeToExtractTypeDataFrom, newSilverlightType);

            IterateAndAddEvents(curCLRTypeToExtractTypeDataFrom, newSilverlightType);

            return newSilverlightType;
        }

        private static void IterateAndAddEvents(Type curCLRTypeToExtractTypeDataFrom, SilverlightType newSilverlightType)
        {
            foreach (EventInfo curEventInfoToConvert in curCLRTypeToExtractTypeDataFrom.GetEvents())
            {
                newSilverlightType.Events.Add(SilverlightEvent.ConvertEventInfoToSilverlightEvent(curEventInfoToConvert, newSilverlightType));
            }
        }

        public static void IterateAndAddMethods(Type curCLRTypeToExtractTypeDataFrom, SilverlightType newSilverlightType)
        {
            foreach (MethodInfo curMethodInfoToConvert in curCLRTypeToExtractTypeDataFrom.GetMethods())
            {
                //if (!(curMethodInfoToConvert.Name.StartsWith("get_")
                //    && curMethodInfoToConvert.Name.StartsWith("set_")
                //    && curMethodInfoToConvert.Name.StartsWith("add_")
                //    && curMethodInfoToConvert.Name.StartsWith("remove_")
                //    ))
                if (!curMethodInfoToConvert.IsSpecialName)
                newSilverlightType.Methods.Add(SilverlightMethod.ConvertMethodInfoToSilverlightMethod(curMethodInfoToConvert, newSilverlightType));
            }
        }

        public static void IterateAndAddProperties(Type curCLRTypeToExtractTypeDataFrom, SilverlightType newSilverlightType)
        {
            foreach (PropertyInfo curPropertyInfoToConvert in curCLRTypeToExtractTypeDataFrom.GetProperties())
            {
                newSilverlightType.Properties.Add(SilverlightProperty.ConvertPropertyInfoToSilverlightProperty(curPropertyInfoToConvert, newSilverlightType));
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
JustinAngel.Net, Senior .Net consultant
Israel Israel
Justin-Josef Angel is a C# Microsoft Most Valuable professional, a Senior .Net consultant in Israel with 4 years of .Net experience and has 8 years of Web experience.

Justin's been working this past year on two Enterprise sized Silverlight projects with his customers. During that time he's gained a real-insight into Silverlight's inner workings and how to integrate Silverlight into the real world of software development. Additionally, During that time he's developed a few well-known projects like the "Silverlight 1.0 Javascript Intellisense", "Silverlight 1.1 Hebrew & Arabic Languages support" and a few others you might know.

Justin is also a seasoned presenter with an impressive track-record of talking in front of thousands of people in Israel.

Justin owns the first .Net blog written in Hebrew - http://www.JustinAngel.Net .
And he also owns an additional blog with mixed Hebrew & English content - http://blogs.Microsoft.co.il/blogs/JustinAngel.

A full list of his articles (all 100+ of them) can be found at: http://www.JustinAngel.Net/#index




Comments and Discussions